﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLVMBAYDomain;

namespace QLVMBAY.UControl
{
    public partial class UcSearch : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                pnTimNC.Visible = false;
                var LstSBay = ClientComm.Ints.SanBay.GetAll(false);
                ddlGiaTri.DataSource = LstSBay;
                ddlGiaTri.DataTextField = "TenSanBay";
                ddlGiaTri.DataValueField = "MaSanBay";
                ddlGiaTri.DataBind();
                ddlGiaTri.Items.Insert(0,new ListItem("Chọn","0"));

            }

        }            

        protected void btnTim1_Click(object sender, EventArgs e)
        {
            if (ddlGiaTri.SelectedValue != "0")
            {
                Session[ClientComm.KEY_TIM_KIEM] = new TTTimKiem() { TimCB = true, MaSB = ddlGiaTri.SelectedValue,TenSB=ddlGiaTri.SelectedItem.Text, ChieuDi = ddlDK.SelectedIndex == 0 };
                Response.Redirect("~/Pages/pKetQuaTim.aspx");
            }
            else
            {
                Page.RegisterStartupScript("Err",
                                         "<script language='javascript'>alert('Vui lòng chọn điều kiện tìm.');</script>");
            }
        }

       

        protected void ddlGia_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtGia.Visible = ddlGia.SelectedIndex >= 2;
        }

        protected void btnTim2_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtGia.Text) || ddlLoaiGhe.SelectedValue != "0" || (ddlNgay.SelectedValue != "0" && ddlThang.SelectedValue != "0"))
            {
                DateTime dTime=DateTime.MinValue;
                if(ddlNgay.SelectedValue!="0" && ddlThang.SelectedValue!="0")
                {
                    dTime=ClientComm.Ints.ToDate(ddlNgay.SelectedValue+"/"+ddlThang.SelectedValue);
                }
                float Gia=0;
                float.TryParse(txtGia.Text,out Gia);
                Session[ClientComm.KEY_TIM_KIEM] = new TTTimKiem() { TimCB = false, DKTim = (DIEU_KIEN_TIM)ddlGia.SelectedIndex, GiaVe = Gia, MaLoaiGhe = ddlLoaiGhe.SelectedValue != "0" ? ddlLoaiGhe.SelectedValue : "",TenLoaiGhe=ddlLoaiGhe.SelectedItem.Text, ThoiGianDi = dTime };
                Response.Redirect("~/Pages/pKetQuaTim.aspx");
            }
            else
            {
                Page.RegisterStartupScript("Err",
                                                       "<script language='javascript'>alert('Vui lòng chọn điều kiện tìm.');</script>");
            }

        }

        protected void ckNangCao_CheckedChanged(object sender, EventArgs e)
        {
            if (ckNangCao.Checked == true)
            {
                ClientComm.Ints.LoadNgay(ddlNgay,true);
                ClientComm.Ints.LoadThang(ddlThang,true);
                var Lst = ClientComm.Ints.LoaiGhe.GetAll(false);
                ddlLoaiGhe.DataSource = Lst;
                ddlLoaiGhe.DataTextField = "TenLoaiGhe";
                ddlLoaiGhe.DataValueField = "MaLoaiGhe";
                ddlLoaiGhe.DataBind();
                ddlLoaiGhe.Items.Insert(0,new ListItem("Chọn", "0"));

            }
            pnTimKiemCoBan.Visible = !ckNangCao.Checked;
            pnTimNC.Visible = ckNangCao.Checked;
        }
    }

        
    
}